import { ActionContext } from "vuex";
import { Counter, RootState } from "../type";

export default {
  namespaced: true,
  state: {
    count: 0,
  },
  getters: {
    oddOrEven(state: Counter) {
      // return state.count % 2 === 1 ? "奇数" : "偶数";
      return (state.count & 1) === 1 ? "奇数" : "偶数";
    },
  },
  actions: {
    increment({ commit }: ActionContext<Counter, RootState>, num: number) {
      commit("INCREMENT", num);
    },
  },
  mutations: {
    INCREMENT(state: Counter, num: number) {
      state.count += num;
    },
  },
};
